{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 全局配置\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# rc: run configure"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 如何配置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 全局配置文件\n",
    "print(matplotlib.matplotlib_fname())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 修改方式一 \n",
    "matplotlib.rcParams['lines.linewidth'] = 2 \n",
    "matplotlib.rcParams['lines.color'] = 'r' \n",
    "\n",
    "# 修改方式二 \n",
    "matplotlib.rc('lines', linewidth=4, color='g') \n",
    "\n",
    "# 恢复默认参数 \n",
    "matplotlib.rcdefaults()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 显示所有默认配置\n",
    "print(matplotlib.rc_params())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 设置显示样式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(plt.style.available)\n",
    "plt.style.use('ggplot')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 常用参数设置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 中文 (不起作用, /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/matplotlibrc)\n",
    "# https://yun.baidu.com/disk/home?#/all?vmode=list&path=%2F%E6%88%91%E7%9A%84%E8%B5%84%E6%BA%90%2F%E5%AD%97%E4%BD%93\n",
    "plt.rcParams['font.sans-serif'] = 'SimHei'\n",
    "# 负号正常显示\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "# 图像显示大小\n",
    "plt.rcParams['figure.figsize'] = (6.0, 6.0)\n",
    "# 使用数学公式 (depend: sudo apt install texlive-full)\n",
    "plt.rcParams['text.usetex'] = True\n",
    "plt.rcParams['text.latex.preamble'] = [r'\\usepackage{amsmath}']\n",
    "# 更多preamble, \\newcommand自定义命令\n",
    "plt.rcParams['text.latex.preamble'] = [\n",
    "    r'\\usepackage{amsmath}',\n",
    "    r'\\usepackage{helvet}',\n",
    "    r'\\usepackage{sansmath}',\n",
    "    r'\\sansmath',\n",
    "    r'\\renewcommand{\\familydefault}{\\sfdefault}',\n",
    "    r'\\usepackage[T1]{fontenc}',\n",
    "    r'\\usepackage{graphicx}',\n",
    "    r'\\usepackage{relsize}',\n",
    "    r'\\newcommand{\\bigpi}{\\scalebox{5}{\\ensuremath{\\pi}}}'\n",
    "]\n",
    "\n",
    "# 坐标label字体大小\n",
    "plt.rcParams['axes.labelsize'] = 16\n",
    "\n",
    "# 图像 插补方式: 紧邻\n",
    "plt.rcParams['image.interpolation'] = 'nearest'\n",
    "# color map\n",
    "plt.rcParams['image.cmap'] = 'gray'\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 其他参数设置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 保存图像像素\n",
    "plt.rcParams['savefig.dpi'] = 300\n",
    "# 图像分辨率\n",
    "plt.rcParams['figure.dpi'] = 300\n",
    "# 设置线条样式\n",
    "plt.rcParams['lines.linestyle'] = '-.'\n",
    "# 设置线条宽度\n",
    "plt.rcParams['lines.linewidth'] = 3\n",
    "# 设置线条标识\n",
    "plt.rcParams['lines.marker'] = 'o'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 坐标设置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 不显示坐标轴\n",
    "plt.axis('off')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
